package com.lcy.demowebsocket.jms;

import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

import javax.jms.Destination;

/**
 * 发布消息
 */
@Service
public class Producer {
    @Autowired // 也可以注入JmsTemplate，JmsMessagingTemplate对JmsTemplate进行了封装
    private JmsMessagingTemplate jmsMessagingTemplate;

    private Destination destination = new ActiveMQTopic("message");

    /**
     * 发送消息
     * @param message
     */
    public void sendMessage(String msg){
        jmsMessagingTemplate.convertAndSend(destination, msg);
    }
}
